//
//  KDWeiboCellFrame.m
//  PublicSentimentMonitorSystem
//
//  Created by 魏强 on 15/11/26.
//  Copyright © 2015年 魏强. All rights reserved.
//

#import "KDWeiboCellFrame.h"
#import "KDWeibo.h"
#import "KDUser.h"
#import "KDWeiboPhotosView.h"
@implementation KDWeiboCellFrame
- (void)setWeibo:(KDWeibo *)weibo{
    _weibo = weibo;
//    KDUser *user = weibo.user;
    //cell的宽度
    CGFloat cellW = screenW;
    
    /** 头像 */
    CGFloat iconWH = 35;
    CGFloat iconX = KDWeiboCellBorderW;
    CGFloat iconY = KDWeiboCellBorderW;
    self.iconViewF = CGRectMake(iconX, iconY, iconWH, iconWH);
    
    /** 昵称 */
    CGFloat nameX = CGRectGetMaxX(self.iconViewF) + KDWeiboCellBorderW;
    CGFloat nameY = iconY;
    CGRect nameRect = [weibo.uname boundingRectWithSize:CGSizeMake(screenW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:KDWeiboCellNameFont} context:nil];
    self.nameLabelF = (CGRect){{nameX, nameY}, nameRect.size};
    
    /** 时间 */
    CGFloat timeX = nameX;
    CGFloat timeY = CGRectGetMaxY(self.nameLabelF) + KDWeiboCellBorderW * 0.5;
    CGRect timeRect = [weibo.created_at boundingRectWithSize:CGSizeMake(screenW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:KDWeiboCellTimeFont} context:nil];
    self.timeLabelF = (CGRect){{timeX, timeY}, timeRect.size};
    
    /** 来源 */
    CGFloat sourceX = CGRectGetMaxX(self.timeLabelF) + KDWeiboCellBorderW;
    CGFloat sourceY = timeY;
    CGRect sourceRect = [weibo.source boundingRectWithSize:CGSizeMake(screenW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:KDWeiboCellSourceFont} context:nil];
    self.sourceLabelF = (CGRect){{sourceX, sourceY}, sourceRect.size};
    
    /** 正文 */
    CGFloat contentX = iconX;
    CGFloat contentY = MAX(CGRectGetMaxY(self.iconViewF), CGRectGetMaxY(self.timeLabelF)) + KDWeiboCellBorderW;
    CGFloat maxW = cellW - 2 * contentX;
    CGRect contentRect = [weibo.text boundingRectWithSize:CGSizeMake(maxW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:KDWeiboCellContentFont} context:nil];
    self.contentLabelF = (CGRect){{contentX, contentY}, contentRect.size};
    
    /** 配图 */
    CGFloat originalH = 0;
    if (weibo.pic_ids.count) { // 有配图
        CGFloat photosX = contentX;
        CGFloat photosY = CGRectGetMaxY(self.contentLabelF) + KDWeiboCellBorderW;
        CGSize photosSize = [KDWeiboPhotosView sizeWithCount:(int)weibo.pic_ids.count andPhotos:weibo.pic_ids];
        self.photosViewF = (CGRect){{photosX, photosY}, photosSize};
        
        originalH = CGRectGetMaxY(self.photosViewF) + KDWeiboCellBorderW;
    } else { // 没配图
        originalH = CGRectGetMaxY(self.contentLabelF) + KDWeiboCellBorderW;
    }
    
    /** 原创微博整体 */
    CGFloat originalX = 0;
    CGFloat originalY = KDWeiboCellMargin *0.5;
    CGFloat originalW = cellW;
    self.originalViewF = CGRectMake(originalX, originalY, originalW, originalH);
    
    CGFloat toolbarY = CGRectGetMaxY(self.originalViewF);
    
    /** 工具条 */
    CGFloat toolbarX = 0;
    CGFloat toolbarW = cellW;
    CGFloat toolbarH = 35;
    self.toolbarF = CGRectMake(toolbarX, toolbarY, toolbarW, toolbarH);
    
    /* cell的高度 */
    self.cellHeight = CGRectGetMaxY(self.toolbarF);
}
@end
